/**
* 版权声明：厦门睿商网络科技有限公司 版权所有 违者必究
* 日    期：2020-08-05
*/
package com.rzico.basics.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.rzico.annotation.Log;
import com.rzico.base.BaseController;
import com.rzico.base.CommResult;
import com.rzico.basics.entity.Enterprise;
import com.rzico.basics.entity.FriendLink;
import com.rzico.basics.service.EnterpriseService;
import com.rzico.basics.service.FriendLinkService;
import com.rzico.entity.PageResult;
import com.rzico.entity.Pageable;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 友情链接控制层
 *
 * @author Rzico Boot
 * @version 1.0
 * @date 2020-08-05
 */
@Api(description = "友情链接接口")
@RestController
@RequestMapping("/friendLink")
public class FriendLinkController extends BaseController {

    @Autowired
    private FriendLinkService friendLinkService;

    /**
     * 分页查询友情链接
     *
     * @return
    */
    @ApiOperation("分页查询友情链接")
    @GetMapping("/list")
    @ApiImplicitParams({ @ApiImplicitParam(name = "mainProductId", value = "主商品ID", dataType = "Long", paramType = "query"),
            @ApiImplicitParam(name = "mainProductType", value = "主商品类型（0.商品，1.量表，2.课程 ,3.报名）", dataType = "Long", paramType = "query")
    })
    public CommResult<FriendLink> list(Long mainProductId,Integer mainProductType, Pageable pageable) {
        Map<String, Object> params = new HashMap<String, Object>();
        params = buildSortField(params, pageable);
        if (mainProductId!=null){
            params.put("mainProductId", mainProductId);
        }
        if (mainProductType!=null){
            params.put("mainProductType", mainProductType);
        }

        Page<Object> startPage = PageHelper.startPage(pageable.getPageNum(), pageable.getPageSize());
        List<FriendLink> list = friendLinkService.selectList(params);
        PageResult<FriendLink> pageResult = new PageResult<FriendLink>(list, startPage.getTotal(), pageable);
        return CommResult.success(pageResult);
    }

}
